// 定义Promise构造函数
function Promise(excutor){
    this.PromiseState = "pending";
    this.PromiseResult = undefined;

    // 声明成功处理内函数
    const success = (value) => {
        this.PromiseState = "fulfilled";
        this.PromiseResult = value;
    }
    const error = (reason) => {
        this.PromiseState = "rejected";
        this.PromiseResult = reason;
    } 

    // 执行excutor函数，要求传递两个函数类型参数
    excutor(success, error);
}

// 在Promise构造函数的原型上添加then方法
Promise.prototype.then = function(onResolved, onRejected){
    // 判断PromiseState状态值来执行对应的参数函数
    if(this.PromiseState === "fulfilled"){
        onResolved(this.PromiseResult);
    }
    if(this.PromiseState === "rejected"){
        onRejected(this.PromiseResult);
    }
}